package com.neardrug.controller;

import com.neardrug.common.Result;
import com.neardrug.controller.dto.NumeratorUpdateDTO;
import com.neardrug.services.NumeratorService;
import com.neardrug.vo.NumeratorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "分子相关")
@RequestMapping("/numerator")
@Slf4j
public class NumeratorController {
    @Resource
    private NumeratorService numeratorService;

    @GetMapping("/{taskId}")
    @ApiOperation("查询分子页面数据")
    public Result selectNumerator(@PathVariable Integer taskId){
        List<NumeratorVO> numeratorVOList = numeratorService.selectNumerator(taskId);
        return Result.success(numeratorVOList);
    }

    @PutMapping
    @ApiOperation("更新分子数据")
    public Result updateNumerator(@RequestBody NumeratorUpdateDTO numeratorUpdateDTO){
        numeratorService.updateNumerator(numeratorUpdateDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除分子数据")
    public Result deleteNumerator(@PathVariable Integer id) {
        numeratorService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping("/del/{taskId}")
    @ApiOperation("删除无编号分子数据")
    public Result deleteNoNumberNumerator(@PathVariable Integer taskId) {
        numeratorService.delNoNumberNumeratorByTaskId(taskId);
        return Result.success();
    }
}
